from rest_framework import serializers

from goods.models import Goods, Brand, GoodsCategory, GoodsSpecification, SpecificationOption


class SPUSerializer(serializers.ModelSerializer):
    """SPU管理"""
    brand = serializers.StringRelatedField(label='品牌名称')
    brand_id = serializers.IntegerField(label='品牌id')
    category1_id = serializers.IntegerField(label='一级分类id')
    category2_id = serializers.IntegerField(label='二级分类id')
    category3_id = serializers.IntegerField(label='三级分类id')

    class Meta:
        model = Goods
        # fields = '__all__'
        exclude = ('create_time', 'update_time', 'category1', 'category2', 'category3')


# 获取品牌信息
class BrandsSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Brand
        fields = ('id', 'name')


# 获取一级分类信息
class ChannelCategoriesSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsCategory
        fields = ('id', 'name')


# 获取规格表列表数据
class SPUSpecsSerializer(serializers.ModelSerializer):
    spu = serializers.StringRelatedField(label='SPU商品名称')
    spu_id = serializers.IntegerField(label='SPU商品id')

    class Meta:
        model = GoodsSpecification
        # fields = '__all__'
        exclude = ('create_time', 'update_time')


# 获取商品规格选项
class GoodsSpecsSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsSpecification
        fields = ('id', 'name')


# 规格选项表列表数据
class SpecsOptionsSerializer(serializers.ModelSerializer):
    spec = serializers.StringRelatedField(label='规格名称')
    spec_id = serializers.IntegerField(label='规格id')

    class Meta:
        model = SpecificationOption
        # fields = '__all__'
        exclude = ('create_time', 'update_time')


class GoodsBrandsSerializer(serializers.ModelSerializer):
    class Meta:
        model = Brand
        fields = ('id', 'name', 'logo', 'first_letter')

